#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define N 660

typedef struct {
    char word[64];
    char meaning[128];
} node;

node dict[N];

int distance(char *a, char *b) {
    int i, j, m, n;
    m = strlen(a);
    n = strlen(b);
    int c[m + 1][n + 1];

    for (i = 0; i <= m; i++)
        c[i][0] = i;
    for (j = 1; j <= n; j++)
        c[0][j] = j;
    for (i = 1; i <= m; i++)
        for (j = 1; j <= n; j++) {
            int u, v, w;
            u = c[i - 1][j] + 1;
            v = c[i][j - 1] + 1;
            w = c[i - 1][j - 1];
            if (a[i - 1] != b[j - 1])
                w++;
            if (u > v) u = v;
            if (u > w) u = w;
            c[i][j] = u;
        }
    return c[m][n];
}


void find(char word[64], int dist) {
    int mark, i, count;
    count = 0;
    for (i = 0; i < N; ++i) {
        mark = distance(word, dict[i].word);
        if (mark <= dist) {
            printf("\t%s\n",dict[i].meaning);
            count++;
        }
    }
    if (count==0){
        printf("无匹配单词！\n");
    }
}

void readdict(char dictname[]) {
    char item[64];
    int i;
    FILE *f = fopen(dictname, "r");
    for (i = 0; i < N; ++i) {
        fscanf(f, "%s", dict[i].word);
        while (fscanf(f, "%s", item), isalpha(item[0]) > 0) {
            strcat(dict[i].word, " ");
            strcat(dict[i].word, item);
        }
        strcpy(dict[i].meaning, item);
    }
    fclose(f);
}

int main(int argc, char *argv[]) {
    char word[64];
    int dist;
    if (argc < 1)
        return 1;
    readdict(argv[1]);
    while (scanf("%s%d", word, &dist) != EOF) {
        find(word, dist);
    }
}

